package com.test.pack1.demo.priorityqueue;

import com.alibaba.fastjson.JSON;
import edu.princeton.cs.algs4.*;

public class TopM {

    public static void main(String[] args) {
        System.out.println(JSON.toJSONString(args));
        int M = Integer.parseInt(args[0]);
        MinPQ<Transaction> pq = new MinPQ<Transaction>(M+1);

        while(StdIn.hasNextLine()){
            pq.insert(new Transaction(StdIn.readLine()));
            if(pq.size()>M){
                pq.delMin();
            }
            Stack<Transaction> stack = new Stack<Transaction>();
            while(!pq.isEmpty())stack.push(pq.delMin());

            System.out.println(stack.size());
            for(Transaction t : stack){
                StdOut.println(t);
            }
        }


    }
}
